
#ifndef TAG_H
#define TAG_H

#include "GraphicsObject.h"
#include "TagBase.h"
#include <QFont>
#include "common.h"
#include "T2C/ProcessVariable.h"
#include <QTextOption>

class Tag : public GraphicsObject, public TagBase
{
    GraphicsObject * owner;
    QFont fnt;

    QString paramStr;
    bool showParamStr;
    QStringList shownPramList;

    QHash< int, ProcessVariable* > pvs;
    typedef QHash< int, ProcessVariable* >::iterator PVIter;

    QTextOption opt;
    ShowParam * sp;

public:
    Tag( GraphicsObject * parent = 0, QString text = ""  );

    void SetFont( QFont f ) { fnt = f; }
    bool HasOwner() { return (bool)owner; }
    bool HasChildren() { return tagList.count(); }
    GraphicsObject * GetParent() { return owner; }

    QString GetParamStr() { return paramStr; }
    void SetParamStr( const QString & s );

    bool ShowParamStr() { return showParamStr; }
    void ShowParamStr( bool shw ) { showParamStr = shw; }

    void UpdateParamStr();
    void SetText( QString t ) { SetTextBase( t ); adjustRect( t ); }

    QStringList * GetShownParamList() { return &shownPramList; }
    void SetShownParamList( const QStringList & l ) { shownPramList.clear(); shownPramList += l; }

    void AddProcessVariable( ProcessVariable * pv );
    void RmProcessVariable( ProcessVariable * pv );
    ProcessVariable * GetProcessVariable( int idf );
    void ClearPVS() { pvs.clear(); }

private:
    QRectF boundingRect() const;
    void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget );

    virtual QVariant itemChange( GraphicsItemChange change, const QVariant &value );

    QString getTagText();
    void adjustRect( const QString & t );
    bool showParam( const QString & param );

};

#endif // TAG_H
